/*
 * Copyright (c) 2015 /5 /20
 * 	      7 :11 : 48
 *               By：wupeiji
 *               Q  Q：757671834
 * 	      It is not easy to meet each other in such a big world
 */

package spring.security.maven.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

/**
 * Created by wpj on 2015/5/20.
 *作者：吴培基
 */
@Component
@Aspect
public class LogAdvice {
    /**

     * 在方法开始前纪录

     * @param jp

     */

    @Before("spring.security.maven.aop.LogPointcut.inServiceLayer()")
    public void logInfo(JoinPoint jp) {

        String className = jp.getThis().toString();

        String methodName = jp.getSignature().getName();   //获得方法名

        System.out.println("=====================================");

        System.out.println("====位于：" + className);

        System.out.println("====调用" + methodName + "方法-开始！");

        Object[] args = jp.getArgs();  //获得参数列表

        if (args.length <= 0) {

            System.out.println("====" + methodName + "方法没有参数");

        } else {

            for (int i = 0; i < args.length; i++) {

                System.out.println("====参数  " + (i + 1) + "：" + args[i]);

            }

        }

        System.out.println("=====================================");

    }


    /**

     * 在方法结束后纪录

     * @param jp

     */

    @After("spring.security.maven.aop.LogPointcut.inServiceLayer()")
    public void logInfoAfter(JoinPoint jp) {

        System.out.println("=====================================");

        System.out.println("====" + jp.getSignature().getName() + "方法-结束！");

        System.out.println("=====================================");

    }
}
